package com.caine.algorithm;

import java.util.Arrays;

public class SelectSortAlgorithm {
    public static void main(String[] args) {
        int arr[] = new int[]{9, 3, 7, 0, 4, 5, 1, 6};
        selectSort(arr);
        printf(arr);
    }

    // 选择排序
    public static void selectSort(int[] arr) {
        int out, in, min;
        for (out = 0; out < arr.length - 1; out++) {
            min = out;
            for (in = out + 1; in < arr.length; in++)
                if (arr[in] < arr[min])
                    min = in;
            swap(arr, out, min);
        }
    }

    public static void swap(int[] arr, int one, int two) {
        int tmp = arr[one];
        arr[one] = arr[two];
        arr[two] = tmp;
    }

    // 选择排序

    // 插入排序

    public static void printf(int[] arr) {
        System.out.println("");
        Arrays.stream(arr).forEach(s -> System.out.print(s + " "));
        System.out.println("");
    }
}
